package filter

import (
	"adam2/internal/properties"
	"anubis-framework/pkg/io"
	"gorm.io/gorm"
)

// 过滤器：上影线占整个涨幅的百分比限制
type UpperShadowPercentageLimitFilter struct {
	db *gorm.DB
}

// 初始化
func (u *UpperShadowPercentageLimitFilter) Init(db *gorm.DB) {
	u.db = db
}

// 执行
func (u *UpperShadowPercentageLimitFilter) DoFilter(transactionDate string) {
	io.Infoln("过滤器：上影线占整个涨幅的百分比限制，交易日期[%s]", transactionDate)
	u.db.Exec("delete from quant_stock_filter q where q.stock_code not in ("+
		"select distinct t.stock_code from quant_stock_filter t "+
		"join stock_transaction_data_all stda on stda.code_=t.stock_code and stda.date_=to_date(?,'yyyy-mm-dd') and stda.highest_price>stda.last_close_price and stda.close_price>stda.last_close_price "+
		"where (stda.highest_price-stda.close_price)/(stda.highest_price-stda.last_close_price)>?)", transactionDate, properties.QuantProperties_.UpperShadowLinePercentage)
}
